<!-- @author zhengjie -->
<template>
    <div class="aisle-box">
        <div class="aisle-ul">
            <div class="aisle-li" v-for="(item, index) in aisleList" :key="index">
                <div>通道：</div>
                <el-input style="width: 90px;" placeholder="0" v-model="item.channel" class="blank-input m-10"></el-input>
                <div style="margin-left: 80px;">工作频率：</div>
                <el-input style="width: 90px;" placeholder="0" v-model="item.freq" class="blank-input m-10"></el-input>
                <div class="lh-40 t-rihgt" style="margin-right: 20px;">MHz</div>
                <img class="aisle-close" src="@/assets/images/close-circle-fill.png" @click="deleteAisle(index)" />

            </div>
            <div class="aisle-add" v-show="aisleList.length < 32">
                <div>添加通道{{ aisleList.length }}/32</div>
                <div class="aisle-button" @click="addAisle">+</div>
            </div>
        </div>
    </div>
</template>
  
<script>
export default {
    name: 'Aisle',
    props: {
        arr: {
            type: Array,
        }
    },
    data() {
        return {
            aisleList: []
        }
    },
    mounted() {
        this.aisleList = this.arr;
        // console.log(this.aisleList);
    },
    watch: {
        aisleList: {
            handler(newList) {
                // 使用深拷贝创建新的数组，以确保监听到数组元素的变化
                this.$emit("setAisleList", JSON.parse(JSON.stringify(newList)));
            },
            deep: true
        },
    },
    methods: {
        closeDialog() {//关闭回调
            // this.$emit("closeAisle", false);
        },
        deleteAisle(index) {
            // 删除数组中对应索引的元素
            this.aisleList.splice(index, 1);
            // this.$emit("setAisleList", this.aisleList);
        },
        addAisle() {
            if (this.aisleList.length < 32) {
                const data = {
                    freq: null,
                }
                this.aisleList.push(data);
            }
        },

    }
}
</script>
  
<style rel="stylesheet/scss" lang="scss" scoped>
.aisle-box {
    background-color: #171D2C;
    height: 450px;
    width: 100%;

    .aisle-ul {
        overflow-x: hidden;
        height: 100%;
        // padding: 10px 20px;
    }

    .aisle-ul::-webkit-scrollbar-track {
        background-color: transparent;
        /* 隐藏滚动条背景色 */
    }

    .aisle-li {
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 5px 0;
        border-bottom: solid 1px #575D73;
        padding: 5px;
    }

    .aisle-close {
        margin-left: auto;
        width: 24px;
        height: 24px;
        cursor: pointer;
    }

    .aisle-add {
        width: 230px;
        text-align: left;
        display: flex;
        align-items: center;
        margin-left: auto;
        margin-top: 10px;

        .aisle-button {
            width: 100px;
            height: 36px;
            background: #46E5CB;
            border-radius: 42px 42px 42px 42px;
            opacity: 1;
            text-align: center;
            line-height: 36px;
            font-size: 18px;
            color: #036EB7;
            margin-left: 20px;
            cursor: pointer;
        }
    }
}
</style>
  